import React from 'react';
import { Toast } from 'antd-mobile'
import { connect } from 'react-redux';


import { getCheckTip } from '../common/service'
import { saveData } from '../action/UserAction'
import NoPowerShow from '../component/NoPowerShow'

class Tip extends React.Component {


	commitConfirm() {
		const { showLoadModal, hideLoadModal } = this.props;
		showLoadModal();
		getCheckTip(this.props.userReducer.flowId) //流程id
		.then((data) => {
			const isOK = data.data;
			console.log(isOK);
			hideLoadModal();
			if (isOK.success) {
				this.props.dispatch(saveData(isOK.obj));
				this.props.currentPage(isOK.obj.flowBaseInfo.flowProcesses);
			} else {
				Toast.info(isOK.msg, 2);
			}
		})
		.catch((e) => {
			hideLoadModal();
			Toast.info('服务器异常', 2);
		})
	}
  
	render() {
		//判断是不是当前节点
		if (this.props.currentObj.flowId !== 6 || -1 === this.props.userReducer.roles.findIndex((value) => value === 61) || -1 === this.props.userReducer.roles.findIndex((value) => value === 62) || !this.props.isTodayStep()) {
			return (<NoPowerShow id={this.props.currentObj.flowId}></NoPowerShow>);
		}
		return (
			<div style={{padding: '4.68rem 0.2rem 0 0.2rem'}}>
				<div 
					id='tipButton'
					className='tip-Button'
					onTouchStart={()=>{document.getElementById('tipButton').style.backgroundColor = '#D97442'}}
					onTouchEnd={()=>{document.getElementById('tipButton').style.backgroundColor = '#FFA24A'}}
					onClick={()=>{
						this.commitConfirm()
					}}
					>
					标识摆放完毕
				</div>
			</div>
		);
	}
}


function mapStateToProps(state) {
  const { userReducer } = state;
  return {
    userReducer
  };
}

export default connect(mapStateToProps)(Tip);